package org.systm.menu.dao;

import org.global.basic.CurdFindRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.systm.menu.entity.Menu;

@Repository
public interface MenuStore extends CurdFindRepository<Menu, String> {

    @Query(value = "SELECT T3.ids_ cid FROM\n" +
            "\t(SELECT @ids \\:= ?1 ) T1,\n" +
            "\t(\n" +
            "\t\tSELECT \n" +
            "\t\t\t(SELECT @ids \\:= GROUP_CONCAT(id) FROM sys_menu WHERE FIND_IN_SET(pid, @ids)) T2,\n" +
            "\t\t\t@ids ids_\n" +
            "\t\tFROM sys_menu\n" +
            "\t) T3\n" +
            "WHERE T3.ids_ IS NOT NULL", nativeQuery = true)
    String cid(String id);
}
